package com.hollycrm.ahunicom.sheet.monitor.hibernate;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

import org.springframework.orm.hibernate.HibernateCallback;
import org.springframework.orm.hibernate.HibernateTemplate;
import org.springframework.orm.hibernate.support.HibernateDaoSupport;
import com.hollycrm.springframework.factory.DefaultBeanFactory;
import com.hollycrm.unicom.common.PageViewObject;
import com.hollycrm.unicom.sheet.BeanResource;
import com.hollycrm.unicom.sheet.Constants;
import com.hollycrm.unicom.sheet.domain.MainSheet;
import com.hollycrm.unicom.sheet.code.CodeManager;
import com.hollycrm.unicom.code.GeneralCode;
import com.hollycrm.unicom.sheet.domain.SmsSend;
import com.hollycrm.unicom.sheet.flow.SheetMove;
import com.hollycrm.unicom.sheet.monitor.MonitorDeptInfo;
import com.hollycrm.unicom.sheet.monitor.MonitorSheetJob;
import com.hollycrm.unicom.sheet.monitor.SheetMonitorItem;
import com.hollycrm.unicom.usersupport.DepartmentTreeViewObject;
import com.hollycrm.unicom.usersupport.User;
import com.hollycrm.unicom.usersupport.hibernate.HibernateUserSupportHelper;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Query;
import net.sf.hibernate.Session;
import com.hollycrm.unicom.usersupport.Role;

public class HibernateMonitorMainPreAlertJobImpl
    extends HibernateMonitorSheetJob {
  public void checkAlerts() throws Exception {
	  System.out.println(
      "Main  PreAlert ---- the ScheduleJob and the pure bean method invoking !");
	  final HibernateTemplate ht=getHibernateTemplate();
	  ht.execute(new HibernateCallback(){
		  List mainPre_ls=new ArrayList();
		  public Object doInHibernate(Session session)throws HibernateException{
			  SimpleDateFormat df=(SimpleDateFormat)DefaultBeanFactory.getBean("dateFormatYear2second");
			  String currentTime=df.format(new Date());
			  String lessTime=df.format(new Date(System.currentTimeMillis()+120*60*1000L));
			  Query qry=session.createQuery(MAIN_RETRIEVE_TIMEOUT_P_SHEETS);
			  qry.setString("lessTime",lessTime);
			  qry.setString("currentTime",currentTime);
			  qry.setString("alertFlag",Constants.SHEET_ALERT_TYPE_COMM);
			  qry.setString("sheetStage",Constants.SHEET_STAGE_NOSTAGE);
			  qry.setString("endStage",Constants.SHEET_STAGE_END);
			  mainPre_ls =qry.list();
			  monitorMainProcessAlert(session, mainPre_ls, Constants.SHEET_ALERT_TYPE_COMM,
                    currentTime);
      return null;
		  }
    });
  }

}
